#include "StdAfx.h"
#include "RandomFrequencyProvider.h"
#include "Randomizer.h"

static Randomizer random;

RandomFrequencyProvider::RandomFrequencyProvider(unsigned int lowFrequencyBound, unsigned int highFrequencyBound, unsigned int minSlices, unsigned int maxSlices)
{
	this->lowFrequncyBound = lowFrequencyBound;
	this->highFrequncyBound = highFrequencyBound;
	this->minSlices = minSlices;
	this->maxSlices = maxSlices;
	curSliceIdx = 0;
	curSliceCount = 0;
	lastFrequency = 0;
}

RandomFrequencyProvider::~RandomFrequencyProvider(void)
{
}

unsigned int RandomFrequencyProvider::GetFrequency(short* sample, unsigned int length, std::vector<SampleMarker>* markers)
{
	if(curSliceIdx>=curSliceCount)
	{
		//time for a new slice counter and a new frequency
		curSliceCount = random.NextInt(minSlices, maxSlices-1);
		curSliceIdx = 0;		
		lastFrequency = (random.NextInt(lowFrequncyBound, highFrequncyBound) + lastFrequency) / 2;
	}
	else
	{
		//time for 
		curSliceIdx++;
	}
	return lastFrequency;
}